package com.wltjack.common.exception.exceptions;

import com.wltjack.common.exception.code.ErrorCode;
import com.wltjack.common.exception.code.SysErrorEnums;
import com.wltjack.common.util.StringUtils;

/**
 * @ClassName BaseException
 * @Description 基础异常
 * @Author kangliang
 * @Date 2021/03/02 21:26
 * @Version 1.0
 */
public class BaseException extends RuntimeException {

    private static final long serialVersionUID = 5692243177785821696L;
    private ErrorCode error;
    private Object data;

    public BaseException() {
        this.data = "";
        this.error = SysErrorEnums.SERVICE_ERROR;
    }

    public BaseException(ErrorCode error) {
        this(error, error.getMessage(), "");
    }

    public BaseException(ErrorCode error, String msg) {
        this(error, msg, "");
    }

    public BaseException(ErrorCode error, String msg, Object data) {
        super(msg);
        this.data = "";
        this.error = error;
        String curMsg = msg;
        if (StringUtils.isNotBlank(msg)) {
            this.error.setMessage(curMsg);
        }

        this.data = data;
    }

    public ErrorCode getError() {
        return this.error;
    }

    public Object getData() {
        return this.data;
    }
}
